package No101_200.No161_170.ExcelSheetColumnTitle_168;

public class Solution {
	/*
	 * Given a positive integer, return its corresponding column title as appear in an Excel sheet.
	 * For example:
	 * 1 -> A
	 * 2 -> B
	 * 3 -> C
	 * ...
	 * 26 -> Z
	 * 27 -> AA
	 * 28 -> AB 
	 * 
	 * */
	public String convertToTitle(int n) {
        int[] a = new int[27];
        for(int i = 1; i < 27;i++){
            a[i] = 'A'+i-1;
        }
        String s = "";
        while(n!=0){
//        	System.out.println(n);
            int y = n%26;//余数
            n = n/26;//商
            if(n != 0 && y == 0){//末尾为0，商退一位给末位
                n = n-1;
                y = 26;
            }
            s = (char)a[y] + s;
        }
        return s;
    }
	
	public static void main(String[] args) {
		Solution s = new Solution();
		System.out.println(s.convertToTitle(27));
	}
}
